﻿using System;
using System.Linq;
using System.ServiceModel;
using log4net;

// Links:
// http://forums.silverlight.net/t/146135.aspx
// http://localhost:27715/MVVMtutorialAdvanced-Web-DomainServiceBook.svc
// http://weblogs.asp.net/fredriknormen/archive/2009/11/27/wcf-ria-services-binding-deep-dive.aspx
// http://blogs.msdn.com/b/saurabh/archive/2009/11/23/understanding-the-wcf-in-wcf-ria-services.aspx
// neuer: http://burcakcakiroglu.com/?p=2148
// Basierend auf Blogs und NHIbernate 3.0 Cookbook
// http://avingtonsolutions.com/blog/post/2008/08/02/Uisng-Unity-with-a-WCF-Service.aspx
// http://devlicio.us/blogs/derik_whittaker/archive/2011/02/03/how-to-intercept-a-wcf-message-to-track-message-size.aspx

namespace MVVMtutorialAdvanced.Web
{
	public class DomainServiceHostFactoryEx : System.ServiceModel.DomainServices.Hosting.DomainServiceHostFactory
	{
		protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
		{
			log4net.Config.XmlConfigurator.Configure();

			ILog log = LogManager.GetLogger(typeof(DomainServiceHostFactoryEx));
			log.DebugFormat("CreateServiceHost");

			return new System.ServiceModel.DomainServices.Hosting.DomainServiceHost(serviceType, FilterAddresses(baseAddresses));
		}

		private static Uri[] FilterAddresses(Uri[] baseAddresses)
		{
			return baseAddresses.GroupBy(uri => uri.Scheme).SelectMany(uri => uri).ToArray();
		}
	}
}